package com.sceneworker.extensions.roundedbox;

import com.acarter.propertytable.Property;
import com.acarter.propertytable.PropertySection;
import com.acarter.scenemonitor.propertydescriptor.propertyobject.Vector3fPropertyObject;
import com.jme.math.Vector3f;
import com.jme.scene.Spatial;
import com.jme.scene.shape.RoundedBox;
import com.jme2utils.staticutils.GenericJMEUtils;
import com.sceneworker.extensions.trimesh.TriMeshPropertyPage;

public class RoundedBoxPropertyPage extends TriMeshPropertyPage {

	public RoundedBoxPropertyPage() {
		super();
		
		PropertySection section = new PropertySection("RoundedBox");
		
		section.addProperty(new Property("Extent", new Vector3fPropertyObject()));
		section.addProperty(new Property("Border", new Vector3fPropertyObject()));
		section.addProperty(new Property("Slope", new Vector3fPropertyObject()));
		
		model.addPropertySection(0, section);
	}
	
	@Override
	protected void updateListeners(final Spatial spatial) {

		super.updateListeners(spatial);
		
		if(!(spatial instanceof RoundedBox)) { return; }
		
		final	RoundedBox		lcl_box = (RoundedBox)spatial;

		PropertySection		lcl_boxSection = model.getPropertySection("RoundedBox");

		Vector3fPropertyObject		lcl_extent = (Vector3fPropertyObject)lcl_boxSection.getProperty("Extent").getPropertyObject();
		lcl_extent.SetListener(new Vector3fPropertyObject.I_Vector3fPropertyObjectListener() {

			public Vector3f readValue() {
				return lcl_box.getExtent();
			}

			public void saveValue(Vector3f value) {
				GenericJMEUtils.updateGeometry(lcl_box, value, lcl_box.getBorder(), lcl_box.getSlope());
			}

		});
		
		Vector3fPropertyObject		lcl_border = (Vector3fPropertyObject)lcl_boxSection.getProperty("Border").getPropertyObject();
		lcl_border.SetListener(new Vector3fPropertyObject.I_Vector3fPropertyObjectListener() {

			public Vector3f readValue() {
				return lcl_box.getBorder();
			}

			public void saveValue(Vector3f value) {
				GenericJMEUtils.updateGeometry(lcl_box, lcl_box.getExtent(), value, lcl_box.getSlope());
			}

		});
		
		Vector3fPropertyObject		lcl_slope = (Vector3fPropertyObject)lcl_boxSection.getProperty("Slope").getPropertyObject();
		lcl_slope.SetListener(new Vector3fPropertyObject.I_Vector3fPropertyObjectListener() {

			public Vector3f readValue() {
				return lcl_box.getSlope();
			}

			public void saveValue(Vector3f value) {
				GenericJMEUtils.updateGeometry(lcl_box, lcl_box.getExtent(), lcl_box.getBorder(), value);
			}

		});
		

	}
}
